local skynet = require "skynet"
local cluster = require "skynet.cluster"
require "skynet.manager"

local filelog = require "filelog"
local configdao = require "configdao"
local nodename = "fqzsnode"

skynet.start(function()
	skynet.error(nodename .. " start")
    math.randomseed(os.time())
	skynet.newservice("nodelog")
	local confsharesvr = skynet.newservice("confshare")
	skynet.call(confsharesvr, "lua", "start")

	local nodeconf = configdao.get_cfgsvrs_key(nodename)
    if nodeconf and nodeconf.debug_console_port then
	    skynet.newservice("debug_console", nodeconf.debug_console_port)
    end

	local timersvr = skynet.newservice("timercenter")
	skynet.call(timersvr, "lua", "init",nodeconf.timersize or 2000)  -- 默认是1000

    skynet.name(".gmmqredis", skynet.newservice("redisdb"))	
	skynet.call(".gmmqredis", "lua", "init", configdao.get_cfgsvrs_key("gmmqredis"))

    --启动机器人管理服务
    skynet.name(".robotmgr",skynet.uniqueservice("robotmgr"))

    --启动奖池管理服务
    skynet.name(".jackpotmgr",skynet.uniqueservice("jackpotmgr"))

    --启动slot管理服务
    skynet.name(".slotmgr", skynet.uniqueservice("slotmgr"))

    --节点唯一id
    skynet.name(".nodeuuid", skynet.uniqueservice("nodeuuid"))

    -- 游戏数据日志服务
    skynet.name(".gametablelog", skynet.newservice("datalog"))   
    skynet.call(".gametablelog", "lua", "init","gamedata")

    -- 牌局记录日志服务
    skynet.name(".tablerecordlog", skynet.newservice("tabledatalog"))   
    skynet.call(".tablerecordlog", "lua", "init","tablerecord")

    --游戏钻石日志服务
    skynet.name(".diamondlog", skynet.newservice("datalog"))
	skynet.call(".diamondlog", "lua", "init", "diamond")

	skynet.name(".router", skynet.uniqueservice("router"))
	skynet.call(".router", "lua", "init_table_pool", nodeconf)
	cluster.open(nodename)

    --[[
	local pbcservice = skynet.uniqueservice("pbcservice")
    skynet.call(pbcservice, "lua", "initproto", "../proto/primary.proto")
    skynet.call(pbcservice, "lua", "initproto", "../fqzsnode/fqzs.proto")
    skynet.name(".agentmgr", skynet.uniqueservice("agentmgr"))
	skynet.call(".agentmgr", "lua", "cmd", "start", {
		port = nodeconf.svr_port,
		maxclient = nodeconf.maxclient or 10000,
		nodelay = true,
		agentsize = nodeconf.agentsize or 20,
		agentincr = nodeconf.agentincr or 10,
	})
    ]]

    --通知gate初始化
    skynet.pcall(cluster.send,"gatenode", ".router", "gamenode_init", nodename)

	skynet.exit()
end)
